package com.example.android.accelerometerplay;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan;
import android.text.style.MaskFilterSpan;
import android.text.style.ScaleXSpan;
import android.text.style.StrikethroughSpan;
import android.text.style.StyleSpan;
import android.text.style.TypefaceSpan;
import android.text.style.URLSpan;
import android.text.style.UnderlineSpan;
import android.widget.TextView;

public class TextTestActivity extends Activity{
	
	private TextView m_pChild_Txt_Test = null;
	private TextView m_pChild_Txt_Test02 = null;
	private TextView m_pChild_Txt_Test03 = null;
	private TextView m_pChild_Txt_Test04 = null;
	private TextView m_pChild_Txt_Test05 = null;
	private TextView m_pChild_Txt_Test06 = null;
	private TextView m_pChild_Txt_Test07 = null;
	private TextView m_pChild_Txt_Test08 = null;
	private TextView m_pChild_Txt_Test09 = null;
	private TextView m_pChild_Txt_Test10 = null;
	private TextView m_pChild_Txt_Test11 = null;
	private TextView m_pChild_Txt_Test12 = null;
	private TextView m_pChild_Txt_Test13 = null;
	private TextView m_pChild_Txt_Test14 = null;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle(R.string.STR_0001);
        setContentView(R.layout.text_test);
        
        InitScreen();
    }
	
	private void InitScreen() {
		if (null == m_pChild_Txt_Test) {
			m_pChild_Txt_Test = (TextView) findViewById(R.id.text_test_t01);
			m_pChild_Txt_Test.setText("Text");
		}
		
		if (null == m_pChild_Txt_Test02) {
			m_pChild_Txt_Test02 = (TextView) findViewById(R.id.text_test_t02);
			m_pChild_Txt_Test02.setText(Html.fromHtml("Reg<sup>&#174;</sup>"));
		}
		
		if (null == m_pChild_Txt_Test03) {
			m_pChild_Txt_Test03 = (TextView) findViewById(R.id.text_test_t03);
			m_pChild_Txt_Test03.setText("Shoadow");
			m_pChild_Txt_Test03.setShadowLayer(3, 1, 2, Color.RED);
		}
		
		if (null == m_pChild_Txt_Test04) {
			m_pChild_Txt_Test04 = (TextView) findViewById(R.id.text_test_t04);
			m_pChild_Txt_Test04.setText("Background Color");
			m_pChild_Txt_Test04.setBackgroundColor(Color.BLUE);
		}
		
		if (null == m_pChild_Txt_Test05) {
			m_pChild_Txt_Test05 = (TextView) findViewById(R.id.text_test_t05);
			m_pChild_Txt_Test05.setText("Text Color");
			m_pChild_Txt_Test05.setTextColor(Color.GREEN);
		}
		
		if (null == m_pChild_Txt_Test06) {
			m_pChild_Txt_Test06 = (TextView) findViewById(R.id.text_test_t06);
			m_pChild_Txt_Test06.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
			m_pChild_Txt_Test06.setText(Html.fromHtml("<a href='http://www.google.com/'>www.google.com</a>"));
			m_pChild_Txt_Test06.setMovementMethod(LinkMovementMethod.getInstance()); 
		}
		
		if (null == m_pChild_Txt_Test07) {
			m_pChild_Txt_Test07 = (TextView) findViewById(R.id.text_test_t07);
//			SpannableString ss = new SpannableString("红色打电话斜体删除线绿色下划线图片:.");
//	        ss.setSpan(new ForegroundColorSpan(Color.RED), 0, 2,
//	                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//	        ss.setSpan(new URLSpan("tel:4155551212"), 2, 5,
//	                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//	        ss.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 5, 7,
//	                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//	        ss.setSpan(new StrikethroughSpan(), 7, 10,
//	                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//	        ss.setSpan(new UnderlineSpan(), 10, 16,
//	                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//	        ss.setSpan(new ForegroundColorSpan(Color.GREEN), 10, 15,
//	                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//	        Drawable d = getResources().getDrawable(R.drawable.icon);
//	        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
//	        ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
//	        ss.setSpan(span, 18, 19, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
			String strValue = "Tel:123456";
			SpannableString ss = new SpannableString(strValue);
			ss.setSpan(new URLSpan("tel:123456"), 0, strValue.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
			ss.setSpan(new ForegroundColorSpan(Color.YELLOW), 0, strValue.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
			m_pChild_Txt_Test07.setText(ss);
	        m_pChild_Txt_Test07.setMovementMethod(LinkMovementMethod.getInstance());
		}
		
		if (null == m_pChild_Txt_Test08) {
			m_pChild_Txt_Test08 = (TextView) findViewById(R.id.text_test_t08);
			String strValue = "BOLD ITALIC";
			SpannableString ss = new SpannableString(strValue);
			ss.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, strValue.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
			m_pChild_Txt_Test08.setText(ss);
			m_pChild_Txt_Test08.setMovementMethod(LinkMovementMethod.getInstance()); 
		}
		
		if (null == m_pChild_Txt_Test09) {
			m_pChild_Txt_Test09 = (TextView) findViewById(R.id.text_test_t09);
			String strValue = "Under Line";
			SpannableString ss = new SpannableString(strValue);
			ss.setSpan(new UnderlineSpan(), 0, strValue.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
			m_pChild_Txt_Test09.setText(ss);
		}
		
		if (null == m_pChild_Txt_Test10) {
			m_pChild_Txt_Test10 = (TextView) findViewById(R.id.text_test_t10);
			String strValue = "Delete Line";
			SpannableString ss = new SpannableString(strValue);
			ss.setSpan(new StrikethroughSpan(), 0, strValue.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
			m_pChild_Txt_Test10.setText(ss);
			m_pChild_Txt_Test10.setTextColor(Color.RED);
		}
		
		if (null == m_pChild_Txt_Test11) {
			m_pChild_Txt_Test11 = (TextView) findViewById(R.id.text_test_t11);
			String strValue = "Image : ";
			SpannableString ss = new SpannableString(strValue);
	        Drawable d = getResources().getDrawable(R.drawable.icon);
	        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
	        ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
	        ss.setSpan(span, strValue.length() - 1, strValue.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
	        m_pChild_Txt_Test11.setText(ss);
		}
		
		if (null == m_pChild_Txt_Test12) {
			m_pChild_Txt_Test12 = (TextView) findViewById(R.id.text_test_t12);
	        m_pChild_Txt_Test12.setText("Move aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk");
	        m_pChild_Txt_Test12.setHorizontallyScrolling(true);
		}
		
		if (null == m_pChild_Txt_Test13) {
			m_pChild_Txt_Test13 = (TextView) findViewById(R.id.text_test_t13);
			String strValue = "1/2X Size Text";
			SpannableString ss = new SpannableString(strValue);
			ss.setSpan(new ScaleXSpan((float) 0.5), 0, strValue.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
			m_pChild_Txt_Test13.setText(ss);
		}
		
		if (null == m_pChild_Txt_Test14) {
			m_pChild_Txt_Test14 = (TextView) findViewById(R.id.text_test_t14);
			Typeface typeFace = Typeface.createFromAsset(getAssets(),"fonts/nation_b.ttf");
			m_pChild_Txt_Test14.setTypeface(typeFace);
			m_pChild_Txt_Test14.setText("Nation : Hello world");
		}
	}
}
